const OPUS_EVENT = {
    "OPUS_INIT_WORKER_EVT": 0x0100,
    "OPUS_START_ENCODE_EVT": 0x0200,
    "OPUS_ENCODE_DATA_EVT": 0x0300,
    "OPUS_STOP_ENCODE_EVT": 0x0400,
    "OPUS_START_DECODE_EVT": 0x0500,
    "OPUS_DECODE_DATA_EVT": 0x0600,
    "OPUS_STOP_DECODE_EVT": 0x0700,
    "OPUS_PAUSE_DECODE_EVT": 0x0800
}

const OPUS_REQ_EVT = 0x01;
const OPUS_RSP_EVT = 0x02;
const OPUS_IND_EVT = 0x03;

function buildOpusEventReq(event, data) {
    let req = {};
    req.event = event| OPUS_REQ_EVT;
    req.data = data;
    return req;
}

function buildOpusEventRsp(event, data) {
    let rsp = {};
    rsp.event = event | OPUS_RSP_EVT;
    rsp.data = data;
    return rsp;
}

function buildOpusEventInd(event, data) {
    let ind = {};
    ind.event = event | OPUS_IND_EVT;
    ind.data = data;
    return ind;
}

function getEventName(event) {
    let result = event.toString(16) + ":";
    if ((event & 0xFF) === OPUS_REQ_EVT) {
        result += "REQ:";
    }else if ((event & 0xFF) === OPUS_IND_EVT) {
        result += "IND:";
    }else if ((event & 0xFF) === OPUS_RSP_EVT) {
        result += "RSP:";
    }

    for (let k in OPUS_EVENT) {
        if (OPUS_EVENT[k] === (event & 0xFF00)) {
            return result + k;
        }
    }

    return "";
}

export {OPUS_EVENT, OPUS_REQ_EVT, OPUS_RSP_EVT, OPUS_IND_EVT,
    buildOpusEventReq, buildOpusEventRsp, buildOpusEventInd, getEventName}